package com.example.icedcap.topeka_fake.helper;

import android.app.Activity;
import android.util.Pair;
import android.view.View;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Author: doushuqi
 * Date: 15/7/18
 * Time: 上午11:43
 * Email: shuqi.dou@singuloid.com
 */
public class TransitionHelper {

    public static Pair[] createSafeTransitionParticipants(Activity activity, boolean includeStatusBar, Pair... otherParticipants) {

        View decor = activity.getWindow().getDecorView();
        View statusBar = null;
        if (includeStatusBar) {
            statusBar = decor.findViewById(android.R.id.statusBarBackground);
        }
        View navBar = decor.findViewById(android.R.id.navigationBarBackground);
        List<Pair> participants = new ArrayList<>(3);
        addNonNullViewToTransitionParticipants(statusBar, participants);
        addNonNullViewToTransitionParticipants(navBar, participants);
        if (otherParticipants != null && !(otherParticipants.length == 1
                && otherParticipants[0] == null)) {
            participants.addAll(Arrays.asList(otherParticipants));
        }

        return participants.toArray(new Pair[participants.size()]);
    }

    private static void addNonNullViewToTransitionParticipants(View view, List<Pair> participants) {
        if (null == view) {
            return;
        }
        participants.add(new Pair<>(view, view.getTransitionName()));
    }
}
